package com.qinggeng.project.api.utils;

import com.google.common.collect.Sets;
import com.qinggeng.common.utils.DateUtils;
import com.qinggeng.common.utils.StringUtils;
import com.vdurmont.emoji.Emoji;
import com.vdurmont.emoji.EmojiParser;
import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.recognition.impl.StopRecognition;
import org.ansj.splitWord.analysis.BaseAnalysis;
import org.ansj.splitWord.analysis.IndexAnalysis;
import org.ansj.splitWord.analysis.NlpAnalysis;
import org.ansj.splitWord.analysis.ToAnalysis;

import java.util.*;


/**
 * @author 吴鹏飞
 * @date 2020/9/21
 * 分词工具
 */
public class ParticipleUtils {
    public static void test() {
        //只关注这些词性的词
        Set<String> expectedNature = new HashSet<String>() {{
            add("n");
            add("v");
            add("vd");
            add("vn");
            add("vf");
            add("vx");
            add("vi");
            add("vl");
            add("vg");
            add("nt");
            add("nz");
            add("nw");
            add("nl");
            add("ng");
            add("userDefine");
            add("wh");
        }};

        StopRecognition filter = new StopRecognition();
        filter.insertStopWords(" ");
        String str = "四川蒲江红心猕猴桃15颗单果约70-90g奇异果孕妇新鲜水果当季弥猴桃 15个装";
        Result recognition = ToAnalysis.parse(str).recognition(filter);
        System.out.println(recognition);
        for (int i = 0; i < recognition.size(); i++) {
            String word = recognition.getTerms().get(i).getName();
            String natureStr = recognition.getTerms().get(i).getNatureStr();
            if (word.length() == 1) {
                recognition.getTerms().remove(i);
            } else {
                if (expectedNature.contains(natureStr)) {
                    System.out.println(word + ":" + word.length());
                }
            }

        }
    }

    public static void main(String[] args) {
        String time = " 00:05:00";
        String time1 = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, DateUtils.addDays(new Date(), -1))+time;
        String time2 = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())+time;
        System.out.println(time1);
        System.out.println(time2);
    }

    //对名城
    public static List<String> participleName(String goodsName) {
        //只关注这些词性的词
        Set<String> expectedNature = new HashSet<String>() {{
            add("n");
            add("v");
            add("vd");
            add("vn");
            add("vf");
            add("vx");
            add("vi");
            add("vl");
            add("vg");
            add("nt");
            add("nz");
            add("nw");
            add("nl");
            add("ng");
            add("wh");
        }};
        StopRecognition filter = new StopRecognition();
        filter.insertStopWords(" ");
        filter.insertStopWords(",");
        Result recognition = ToAnalysis.parse(goodsName).recognition(filter);

        List<String> keywordsList = new ArrayList<>();
        for (int i = 0; i < recognition.getTerms().size(); i++) {
            String word = recognition.getTerms().get(i).getName();
            String natureStr = recognition.getTerms().get(i).getNatureStr();
            if ( word.length() != 1 && expectedNature.contains(natureStr)) {
                keywordsList.add(word);
            }
        }
        return keywordsList;
    }
}
